package com.weiyin.examination.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.weiyin.examination.R;
import com.weiyin.examination.util.LayoutHelper;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * <pre>
 *     e-mail : niejunfeng@win-electr.com
 *     time   : 2018/04/04
 *     desc   :
 *     version: 1.0.0
 *     Copyright: Copyright（c）2017
 *     Company:上海蔚音电子科技有限公司
 * </pre>
 *
 * @author niejunfeng
 */
public class TopicsAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private Activity activity;
    private String type;

    public TopicsAdapter(Activity activity, int layoutResId, @Nullable List<String> data, String type) {
        super(layoutResId, data);
        this.activity = activity;
        this.type = type;
    }

    @Override
    protected BaseViewHolder createBaseViewHolder(View view) {
        LayoutHelper layoutHelper = new LayoutHelper(activity);
        layoutHelper.scaleView(view);
        return super.createBaseViewHolder(view);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(BaseViewHolder baseViewHolder, int position, String type);
    }


    @Override
    protected void convert(final BaseViewHolder helper, String item) {
        if (helper != null && !StringUtils.isEmpty(item)) {
            helper.setText(R.id.topicItemTextView, item);

            helper.getView(R.id.topicItemLayout).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (onItemClickListener != null) {
                        onItemClickListener.onItemClick(helper, helper.getAdapterPosition(), type);
                    }
                }
            });
        }
    }
}
